using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace PackTool
{
    public class AllFileList
    {
        static public bool isDone { get; protected set; }
        public delegate void OnInitEnd();
        public static void init(OnInitEnd end = null)
        {
            isDone = false;
            ResourceDown.Instance.Load("file://" + ResourcesPath.LocalConfigPath + "FilesMD5.csv", LoadEnd, end);
        }

        static public List<string> FileList { get; protected set; }

        static void LoadEnd(WWW www, object p)
        {
            if (FileList != null)
                FileList.Clear();
            else
                FileList = new List<string>();

            Csv.CsvReader csv = new Csv.CsvReader();
            string text = www.text;
            csv.Load(ref text, ',');
            for (int i = 0; i < csv.getYCount(); ++i)
            {
                FileList.Add(csv.getStr(i, 0).Replace('\\', '/'));
            }

            isDone = true;

            if ((p as OnInitEnd) != null)
            {
                ((OnInitEnd)p)();
            }
        }
    }
}